<template>
	<view>
		<view v-if="type=='card'" class="swiper-style-1">
			<swiper class="swiper" 
				:indicator-dots="false" 
				indicator-active-color="rgba(0, 0, 0, 0)" 
				indicator-color="rgba(0, 0, 0, 0)"
				:autoplay="autoplay" interval="5000" 
				@change="onBindChange" :current="current">
				<block v-for="item in list" :key="item">
					<swiper-item class="swiper-item" @click="onSwiperItem">
						<view class="image-cont"><image :src="item.img" mode="aspectFill"></image></view>
					</swiper-item>
				</block>
			</swiper>
			<view class="indicator" v-if="list.length > 1">
				<view class="indicato">
					<block v-for="(item, index) in list" :key="index">
					<view class="item" :style="current == index ? 'background: #49CD82' : 'background:rgba(0,0,0,.1)'"></view>
					</block>
				</view>
			</view>
		</view>

		<view class="swiper-style-2" v-if="type == 'three'">
			<swiper 
				:circular="true"
				:indicator-dots="false" 
				indicator-active-color="rgba(0, 0, 0, 0)" 
				indicator-color="rgba(0, 0, 0, 0)"
				:autoplay="autoplay" interval="5000" 
				@change="onBindChange" 
				:current="current">
				<block v-for="(item, index) in list" :key="index">
					<swiper-item :class="current==index? 'cur':'' ">
						<view class="swiper-item" @click="onArticle(item.url)">
							<view class="swiper-image">
								<view class="title" v-if="item.url && item.title">
									<text>{{item.title}}</text>
								</view>
								<image :src="item.img" mode="aspectFill" />
							</view>
						</view>
					</swiper-item>
				</block>
			</swiper>
			<view class="indicator">
				<block v-for="(item, index) in list" :key="index">
					<view class="item" 
					:style="current==index? ' width: 30rpx;':' width: 15rpx;opacity: .3' "></view>
				</block>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			type: {
				type: String,
				default: 'card'
			},
			list: {
				type: Array
			},
			autoplay: {
				type:Boolean,
				default: false
			}
		},
		watch: {
			autoplay(newVal) {
				if(newVal) {
					this.current = 0
				}
			}
		},
		data() {
			return {
				current: 0
			};
		},
		methods: {
			onBindChange({
				detail: {
					current
				}
			}) {
				this.current = current;
			},
			onArticle(url) {
				if(url) {
					this.onGoNext(`/pages/Column/Strategy/detail/detail?id=${url}`)
				} 
			}
		}
	};
</script>

<style lang="scss">
	.swiper-style-1 {
		width: 100%;
		height: 405upx;
		position: relative;
		margin-bottom: 30upx;

		.swiper {
			width: 100%;
			height: 420upx;
		}

		.swiper-item {
			padding: 0 40upx;
			padding-top: 20upx;
			box-sizing: border-box;
		}

		.image-cont {
			width: 100%;
			height: 370upx;
			border-radius: 12upx;
			box-shadow: 0 5upx 30upx rgba(0, 0, 0, 0.2);
			background-color: #eee;
			overflow: hidden;
		}

		.image-cont>image {
			width: 100%;
			height: 100%;
			overflow: hidden;
		}

		.indicator {
			position: absolute;
			left: 0;
			right: 0;
			bottom: -10upx;
			width: 100%;
		}

		.indicato {
			width: 100%;
			display: flex;
			justify-content: center;
		}

		.indicato>.item {
			width: 30upx;
			height: 4upx;
			background-color: rgba(0, 0, 0, .1);
			margin: 0 10upx;
			border-radius: 4upx;
		}

		.indicato>.on {
			background-color: #00D8A0;
		}
	}


	.swiper-style-2 {
		height: 380rpx;
		position: relative;
		margin-bottom: 20rpx;

		.slide-image {
			width: 100%;
			height: 335rpx;
			border-radius: 10rpx;
			box-shadow: 0px 3px 10px 0px rgba(0, 0, 0, 0.1);
		}

		swiper {
			width: 100%;
			height: 365rpx;

			swiper-item {
				width: 670rpx !important;
				left: 40rpx;
				box-sizing: border-box;
				overflow: initial;
			}

			.swiper-item {
				position: relative;
				display: flex;
				align-items: center;
				justify-content: center;
				transform: scale(.96, .9);
				transition: all 0.2s ease-in 0s;
				overflow: hidden;
				padding: 0 5rpx;
				padding-bottom: 20rpx;
				padding-top: 10rpx;
				.swiper-image{
					width: 100%;
					height: 335rpx;
					border-radius: 10rpx;
					box-shadow: 0px 3px 10px 0px rgba(0, 0, 0, 0.1);
					overflow: hidden;
					position: relative;
					> image{
						width: 100%;
						height: 100%;
						object-fit: cover;
					}
				}
				.title{
					position: absolute;
					border-radius: 10rpx;
					top: 0;
					left: 0;
					bottom: 0;
					right: 0;
					z-index: 5;
					color: #fff;
					box-sizing: border-box;
					background: linear-gradient(rgba(#000,0), rgba(#000,0.5)); 
					display: flex;
					align-items: flex-end;
					padding:  20rpx 30rpx;
					font-size: 35rpx;
					
					> text{
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
					}
				}
			}

			.cur {
				.swiper-item {
					transform: none;
					transition: all 0.2s ease-in 0s;
				}
			}
		}

		.indicator {
			position: absolute;
			bottom: 0;
			left: 0;
			right: 0;
			margin: auto;
			display: flex;
			align-items: center;
			justify-content: center;
			z-index: 2;
		}

		.indicator>.item {
			height: 6rpx;
			border-radius: 6rpx;
			background-color: #49CD82;
			transition: all 0.2s ease-in 0s;
			margin: 0 5rpx;
		}
	}
</style>
